<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header">Danh sách Kinh doanh - Tỉnh Thành</h3>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <a class="" href="<?php echo $this->url(array("action"=>"add")) ?>">Thêm</a>
            </div>
            <div class="panel-body">
                <div class="table-reponsive">
                    <div id="jqxgrid">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields:
                    [
                        { name: 'id',type:'int'},
                       // { name: 'name', type: 'string' },
                       // { name: 'price', type: 'int' },
                        { name: 'area_id', type: 'string' },
                        { name: 'admin_id', type: 'string' },

                        { name: 'order', type: 'int' },
                        { name: 'status', type: 'string' }
                    ],
                url:'<?php echo $this->baseUrl() ?>/admin/adminarea/service',
                sortcolumn: 'order',
                sortdirection: 'asc'
            };
            var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                }
            });
            $("#jqxgrid").jqxGrid(
                {
                    width: '100%',
                    source: dataAdapter,
                    theme: 'bootstrap',
                    pageable: true,
                    showfilterrow: true,
                    filterable: true,
                    autoheight: true,
                    sortable: true,
                    altrows: true,
                    enabletooltips: true,
                    selectionmode: 'multiplecellsadvanced',
                    columnsResize: true,
                    rendergridrows: function (params) {
                        return params.data;
                    },
                    ready: function () {
                        $("#jqxgrid").jqxGrid('hideColumn', 'id');
                    },
                    columns: [
                        {text:  'id',dataField:'id',cellsAlign:'right',width:0},
                        //{ text: 'Tên sản phẩm',editable: false, dataField: 'name', width: '33%' },
                        // { text: 'Giá',editable: false, dataField: 'price', width: '20%' },
                        { text: 'Tỉnh thành',editable: false, dataField: 'area_id', width: '20%' },
                        { text: 'Người dùng',editable: false, dataField: 'admin_id', width: '35%' },
                        { text: 'Thứ tự',editable: false, dataField: 'order', width: '15%' } ,
                        { text: 'Hiển thị',columnType:'checkbox', editable: false, dataField: 'status', width: '10%' },
                        {text: 'Xoá',filtertype: 'none',width:'10%', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                            // render custom column.
                            editrow = row;
                            var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                            var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-trash-o fa-lg'";
                            url = url + "href='#' onclick='return jsdelete("+dataRecord.id+");'></a></div>";
                            return url;
                        }
                        },
                        {text: 'Sửa',filtertype: 'none',width:'10%', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                            // render custom column.
                            editrow = row;
                            var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                            var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-edit fa-lg'";
                            url = url + "href='<?php echo $this->baseUrl()?>/admin/adminarea/edit/id/"+dataRecord.id+"'></a></div>";
                            return url;
                        }
                        }
                    ]
                });

        });
    </script>
    <script type='text/javascript'>
        function jsdelete(id)
        {                        
            bootbox.confirm("Bạn có chắc muốn xoá tỉnh thành này khỏi danh sách quản lý của quản trị viên này không?",
             function(result) {
                 if(result == true)
                 {
                    return window.location = "<?php echo $this->baseUrl() ?>/admin/adminarea/delete/id/"+id;
                 }
            });             
        }
    </script>